package seph;

import java.util.EnumSet;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.Minecraft;
import net.minecraft.src.GuiAchievements;
import net.minecraft.src.KeyBinding;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

public class AchievementKeyHandler extends KeyHandler {

	//Bind
	static KeyBinding bind = new KeyBinding("Achievement" + "Bind", Keyboard.KEY_F7);
	
	//Time
	private long index;
	
	//minecraft
	private Minecraft mc;
	
	public AchievementKeyHandler(Minecraft game){
		super(new KeyBinding[]{bind}, new boolean[]{false});
		this.mc = game;
	}
	
	@Override
	public String getLabel() {
		return "Achievement Bind";
	}

	@Override
	public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
		index = System.currentTimeMillis();
	}

	@Override
	public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
		if (System.currentTimeMillis() > index + 1000) //have we been holding the achievement key for longer then one second?
		{
			Minecraft.getMinecraft().displayGuiScreen(new AchievementOptionsSettings());
		} else {
			//do not bring up the gui if hotkey is false, but still allow the settings menu to show up
			if (AchievementOptions.enableHotkey)
				Minecraft.getMinecraft().displayGuiScreen(new GuiAchievements(mc.statFileWriter));
		}
	}

	@Override
	public EnumSet<TickType> ticks() {
		// TODO Auto-generated method stub
		return EnumSet.of(TickType.CLIENT);
	}

}
